package common.mybatis;

import java.io.Reader;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SqlServiceImpl implements SqlService{

	public SqlSession getSqlSession(boolean autoCommit){
		
		SqlSessionFactory factory = null;
		
		try{
			
			String resource = "common/mybatis/SqlMapConfig.xml";
			Reader reader = Resources.getResourceAsReader(resource);
			
			SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
			factory = builder.build(reader, "mysql");
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return factory.openSession(autoCommit);
	}
}
